import { getBanner } from '../api'

export default {
  namespaced: true,
  state: {
    loading: true,
    record: []
  },
  mutations: {
    setLoading (state, payload) {
      state.loading = payload
    },
    setData (state, payload) {
      state.record = payload
    }
  },
  actions: {
    async fetchBanner (context) {
      // 数据拿到了有数据直接返回
      context.commit('setLoading', false)
      if (context.state.record.length) {
        context.commit('setLoading', true)
        return
      }
      const result = await getBanner()
      console.log(result)
      context.commit('setLoading', true)
      context.commit('setData', result)
    }
  }
}
